<#assign StringUtils = beansWrapperFn.getStaticModels()["org.apache.commons.lang3.StringUtils"]>
SELECT t.*
FROM c1_permission t
WHERE (T.SITE_ID = :siteId or T.SITE_CODE = :siteId)
<#if StringUtils.isNotBlank(typeId)>
AND (T.type_id = :typeId or T.type_code = :typeId)
</#if>
ORDER BY T.site_id, T.type_id, LENGTH(t.code) DESC, t.order_num
